package dst.benchmark;

import time.Timer;

import static stringFunctions.StringFunctions.*;

/**
 *
 * Fully Tested: No
 * Fully Documented: No
 * Created: 22-Mar-2012
 * Last Updated: 22-Mar-2012
 *
 * @author Shimu Wu
 */
public class BenchMarker {

    public void benchMark(BenchMarkable b, int iterations) {
        Timer timer = new Timer(true);
        long average, min, max, elapsed;
        average = 0;
        min = Long.MAX_VALUE;
        max = Long.MIN_VALUE;
        
        for (int i = 0; i < iterations; i++) {
            timer.start();
            b.execute();
            elapsed = timer.stop();
            average += elapsed;
            min = Math.min(min, elapsed);
            max = Math.max(max, elapsed);
        }
        average /= iterations;

        System.out.println(concat( 
                "-------------------------------\n\t", b.getDescription(),
                "\tbenchmark results:\n",
                "\tIterations:", Integer.toString(iterations), "\n",
                "\tAverage time per iteration:",
                Long.toString(average), "milliseconds\n", 
                "\tMinimum time per iteration:", 
                Long.toString(min), "milliseconds\n",
                "\tMaximum time per iteration:",
                Long.toString(max), "milliseconds\n"));
    }
}
